<!-- 引用编辑器 -->
<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<script src="/static/kindeditor/kindeditor-all.js"></script>
<script src="/static/kindeditor/lang/zh-CN.js"></script>
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{$post['title']}</h1>
                <div class="fly-detail-info">
                    <!-- <span class="layui-badge">审核中</span> -->
                    <span class="layui-badge layui-bg-green fly-detail-column">{$post['type']['name']}</span>

                    <!-- 帖子采纳 -->
                    {if $post['accept']}
                    <span class="layui-badge" style="background-color: #5FB878;">已采纳</span>
                    {else}
                    <span class="layui-badge" style="background-color: #999;">未采纳</span>
                    {/if}

                    <!-- 帖子状态 -->
                    {if $post['state'] == 1}
                    <span class="layui-badge layui-bg-orange">置顶</span>
                    {elseif $post['state'] == 2}
                    <span class="layui-badge layui-bg-green">精华</span>
                    {elseif $post['state'] == 3}
                    <span class="layui-badge layui-bg-red">热门</span>
                    {elseif $post['state'] == 0}
                    <span class="layui-badge layui-bg-black">常规</span>
                    {/if}

                    <div class="fly-admin-box" data-id="123">
                        {if $post['userid'] == $userid}
                        <span class="layui-btn layui-btn-xs jie-admin" id="del" data-postid="{$post['id']}"
                            type="del">删除</span>
                        {/if}

                        {if $LoginUser && $post['userid'] != $userid}
                        {if $collect}
                        <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick"
                            data-postid="{$post['id']}" id="collect" rank="0" style="background-color:#ccc;">取消收藏</span>
                        {else}
                        <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick"
                            data-postid="{$post['id']}" id="collect" rank="1">收藏</span>
                        {/if}
                        {/if}
                        <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span> -->

                        <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="1">加精</span> -->
                        <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span> -->
                    </div>
                    <span class="fly-list-nums">
                        <a href="#comment"><i class="iconfont" title="评论量">&#xe60c;</i> {$post['comment_count']}</a>
                        <i class="iconfont" title="访问量" style="user-select: none">&#xe60b;</i> {$post['visit_count']}
                    </span>
                </div>
                <div class="detail-about">
                    <a class="fly-avatar" href="{:url('/home/user/index',['userid' => $post['userid']])}">
                        <img src="{$post['user']['avatar'] ? $post['user']['avatar'] : '/static/home/res/images/avatar/default.png'}"
                            alt="{$post['user']['nickname']}">
                    </a>
                    <div class="fly-detail-user">
                        <a href="{:url('/home/user/index',['userid' => $post['userid']])}" class="fly-link">
                            <cite>{$post['user']['nickname']}</cite>
                            {if $post['user']['auth'] == 1}
                            <i class="iconfont icon-renzheng" title="认证信息：{$post['user']['nickname']}"></i>
                            {/if}
                            <i class="layui-badge fly-badge-vip">VIP {$post['user']['vip']}</i>
                        </a>
                        <span>{$post['createtime']|date="Y-m-d"}</span>
                    </div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{$post['point']}积分</span>
                        {if $post['userid'] == $userid}
                        <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a
                                href="{:url('/home/post/edit',['postid' => $post['id']])}">编辑此贴</a></span>
                        {/if}
                    </div>
                </div>
                <div class="detail-body photos">
                    {$post['content']|raw}
                </div>
            </div>

            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend>
                </fieldset>

                <ul class="jieda" id="jieda">
                    {if count($CommentList) > 0}
                    {:CommentHtml($CommentList,$post,$LoginUser)}
                    {else}
                    <!-- 无数据时 -->
                    <li class="fly-none">消灭零回复</li>
                    {/if}
                </ul>

                <div class="layui-form layui-form-pane">
                    {if $LoginUser && $post.accept == null}
                    <div id="reply" style="font-size: 22px;"></div>
                    <form action="{:url('/home/comment/add')}" method="post">
                        <a name="comment"></a>
                        <div class="layui-form-item layui-form-text">
                            <div class="layui-input-block">
                                <textarea name="content" style="width:100%;height: 260px;"
                                    placeholder="请输入内容"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="postid" value="{$post['id']}">
                            <!-- 评论父级id -->
                            <input type="hidden" name="pid" value="">
                            <button class="layui-btn" lay-submit>提交回复</button>
                        </div>
                    </form>
                    {/if}
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <dl class="fly-panel fly-list-one">
                <dt class="fly-panel-title">本周热议</dt>
                {if count($PostList)>0}
                {foreach $PostList as $item}
                <dd>
                    <a href="{:url('/home/post/info',['postid' => $item['id']])}">{$item.title}</a>
                    <span><i class="iconfont icon-pinglun1"></i> {$item.commentcount}</span>
                </dd>
                {/foreach}
                {else}
                <!-- 无数据时 -->
                <div class="fly-none">没有相关数据</div>
                {/if}
            </dl>

            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="/static/home/res/images/weixin.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注公众号</p>
            </div>

        </div>
    </div>
</div>
<script>
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('textarea[name="content"]');
    })
    layui.use(['layer'], function () {
        var $ = layui.jquery,
            layer = layui.layer;
        //点赞
        $("span[type='zan']").click(function () {
            var LikeCount = parseInt($(this).children('em').text())
            var commentid = $(this).data('id')
            // 把当前对象赋值给全局变量
            var that = $(this)
            $.ajax({
                type: "post",
                url: `{:url('/home/Comment/like')}`,
                data: {
                    commentid
                },
                success: function (res) {
                    if (res.code === 1) {
                        if (that.hasClass('zanok')) {
                            that.removeClass('zanok')

                            that.children('em').text(LikeCount - 1)
                        } else {
                            that.addClass('zanok')

                            that.children('em').text(LikeCount + 1)
                        }
                    }
                }
            })
        })
        // 采纳
        $('.accept').click(function () {
            var commentid = $(this).data('comid')

            layer.confirm('是否采纳该评论？', {
                title: '确认采纳'
            }, function (index) {

                $.ajax({
                    type: "post",
                    url: `{:url('home/comment/accept')}`,
                    data: {
                        commentid
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code === 1) {
                            layer.msg(res.msg, function () {
                                location.reload()
                            })
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                });
                layer.close(index)
            })
        })
        // 回复
        $(".reply").click(function () {
            var pid = $(this).data('pid')

            var nickname = $(this).data('nickname')

            $('input[name="pid"]').val(pid)

            $('#reply').html('回复@' + nickname)
            editor.focus()
        })

        // 删除评论
        $("span[type='del']").click(function () {
            var comid = $(this).data('comid')
            layer.confirm('确认删除该评论？', { icon: 3, title: '删除' }, function (index) {
                $.ajax({
                    type: "post",
                    url: `{:url('home/comment/del')}`,
                    data: {
                        comid
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code === 1) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 600
                            }, function () {
                                location.href = res.url
                            })
                        } else {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 600
                            })
                        }
                    }
                })
                layer.close(index);
            })
        })
        // 删除帖子
        $('#del').click(function () {
            var postid = $(this).data('postid')
            layer.confirm('确认删除该贴？', {
                title: '删除'
            }, function (index) {
                $.ajax({
                    type: "post",
                    url: `{:url('/home/Post/del')}`,
                    data: {
                        postid
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code === 1) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 600
                            }, function () {
                                location.href = res.url
                            })
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                })
            })
        })

        // 收藏帖子/取消收藏
        $('#collect').click(function () {
            var postid = $(this).data('postid')
            $.ajax({
                type: "post",
                url: `{:url('/home/Collect/collect')}`,
                data: {
                    postid
                },
                dataType: "json",
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg(res.msg)
                        if (res.data) {
                            // 收藏操作
                            $('#collect').css({ backgroundColor: '#ccc' }).text('取消收藏')
                        } else {
                            // 取消操作
                            $('#collect').css({ backgroundColor: '#009688' }).text('收藏')
                        }
                    } else {
                        layer.msg(res.msg)
                    }
                }
            });
        })
    })
</script>